package com.rrd.dw.mr.gzip.kafka;

import com.ucredit.babel.common.model.BaseModel;
import com.ucredit.babel.common.model.RecordType;
import com.ucredit.babel.common.model.third.suanhua.*;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper.Context;

import java.io.IOException;

/*
 * 算话综合评分11&综合风险等级
 *
 * @author:szw
 * */

public class SuanHuaCreditScoreRecordParse extends ParseBase {
    Text key = new Text();
    Text val = new Text();

    @Override
    public boolean parseJob(Context context, BaseModel<?> model, String successful) throws IOException, InterruptedException {
        SuanhuaCreditScoreRecord shRecord = (SuanhuaCreditScoreRecord) model;
        SuanhuaCreditScoreData shData = shRecord.getData();

        StringBuilder sb = getBaseInfo(shRecord, successful);
        StringBuilder shSb = new StringBuilder(500);

        // retCode
        shSb.append(shData.getRetCode() == null ? "" : shData.getRetCode()).append(CRT001);
        // retMsg
        shSb.append(shData.getRetMsg() == null ? "" : shData.getRetMsg()).append(CRT001);
        // orgNum
        shSb.append(shData.getOrgNum() == null ? "" : shData.getOrgNum()).append(CRT001);
        SuanhuaCreditScore data = shData.getData();
        Crp1050 crp1050 = data.getCrp1050();
        Crp2020 crp2020 = data.getCrp2020();
        Crp2030 crp2030 = data.getCrp2030();
        // data/appNum
        shSb.append(data.getAppNum() == null ? "" : data.getAppNum()).append(CRT001);
        // data/appDate
        shSb.append(data.getAppDate() == null ? "" : data.getAppDate()).append(CRT001);
        // data/appNo
        shSb.append(data.getAppNo() == null ? "" : data.getAppNo()).append(CRT001);
        // data/appStatus
        shSb.append(data.getAppStatus() == null ? "" : data.getAppStatus()).append(CRT001);
        // data/appValid
        shSb.append(data.getAppValid() == null ? "" : data.getAppValid()).append(CRT001);
        // data/errMsg
        shSb.append(data.getErrMsg() == null ? "" : data.getErrMsg()).append(CRT001);
        // data/appWarn
        shSb.append(data.getAppWarn() == null ? "" : data.getAppWarn()).append(CRT001);
        // data/CRP1050/dataStatus
        shSb.append(crp1050.getDataStatus() == null ? "" : crp1050.getDataStatus()).append(CRT001);
        // data/CRP1050/dataValid
        shSb.append(crp1050.getDataValid() == null ? "" : crp1050.getDataValid()).append(CRT001);
        // data/CRP1050/dataErrMsg
        shSb.append(crp1050.getDataErrMsg() == null ? "" : crp1050.getDataErrMsg()).append(CRT001);
        // data/CRP1050/mhxModelScore
        shSb.append(crp1050.getMhxModelScore() == null ? "" : crp1050.getMhxModelScore()).append(CRT001);
        // data/CRP2020/dataStatus
        shSb.append(crp2020.getDataStatus() == null ? "" : crp2020.getDataStatus()).append(CRT001);
        // data/CRP2020/dataValid
        shSb.append(crp2020.getDataValid() == null ? "" : crp2020.getDataValid()).append(CRT001);
        // data/CRP2020/dataErrMsg
        shSb.append(crp2020.getDataErrMsg() == null ? "" : crp2020.getDataErrMsg()).append(CRT001);
        // data/CRP2020/seLevel
        shSb.append(crp2020.getSeLevel() == null ? "" : crp2020.getSeLevel()).append(CRT001);
        // data/CRP2030/dataStatus
        shSb.append(crp2030.getDataStatus() == null ? "" : crp2030.getDataStatus()).append(CRT001);
        // data/CRP2030/dataValid
        shSb.append(crp2030.getDataValid() == null ? "" : crp2030.getDataValid()).append(CRT001);
        // data/CRP2030/dataErrMsg
        shSb.append(crp2030.getDataErrMsg() == null ? "" : crp2030.getDataErrMsg()).append(CRT001);
        // data/CRP2030/scLevel
        shSb.append(crp2030.getScLevel() == null ? "" : crp2030.getScLevel()).append(CRT001);
        key.set(getKey());
        val.set((sb.toString() + shSb.toString()).replace("\n", " ").replace("\r", " "));
        context.write(key, val);

        return true;
    }

    @Override
    public String getTableName() {
        return "kafka_babel_sh_credit_score_record_inc";
    }

    @Override
    public String getType() {
        return RecordType.SUANHUA_CREDIT_SCORE_RECORD.toString();
    }

    @Override
    public String getComment() {
        return "算话综合评分11&综合风险等级";
    }
}
